﻿$(document).ready(function () {
    var AccountDS = new kendo.data.DataSource({
        type: "json",
        serverPaging: true,
        serverSorting: true,
        pageSize: 10,
        transport: {
            read: {
                url: "/Account/JsonProcess?action=read",
                dataType: "json"
            },
            update: {
                url: "/Account/JsonProcess?action=update",
                dataType: "json",
                complete: function (e) {
                    $("#account-grid").data("kendoGrid").dataSource.read();
                }
            },
            create: {
                url: "/Account/JsonProcess?action=create",
                dataType: "json",
                complete: function (e) {
                    $("#account-grid").data("kendoGrid").dataSource.read();
                }
            },
            destroy: {
                url: "/Account/JsonProcess?action=delete",
                dataType: "json",
                complete: function (e) {
                    $("#account-grid").data("kendoGrid").dataSource.read();
                }
            }
        },
        batch: true,
        schema: {
            data: "data",
            total: "pageSize",
            model: {
                id: "ID",
                fields: {
                    Rowstatus: { nullable: false },
                    Fullname: { nullable: false },
                    Email: { type: "number", nullable: false },
                    SectionID: { nullable: true },
                    JobTitleID: { nullable: true },
                    TTD: { nullable: true },
                    CreatedBy: { nullable: true },
                    CreatedOn: { nullable: true },
                    LastModifiedBy: { nullable: true },
                    LastModifiedOn: { nullable: true }
                }
            }
        }
    });

    $("#account-grid").kendoGrid({
        dataSource: AccountDS,
        toolbar: ["create"],
        columns: [
            { command: ["edit", "destroy"], title: "&nbsp;", width: 190, attributes: { style: "text-align: center"} },
            { title: "Active", field: "Rowstatus", width: 80, attributes: { style: "text-align: center" } }
        ],
        editable: 'inline',
        groupable: true,
        sortable: true,
        resizable: true,
        pageable: {
            refresh: true,
            pageSizes: true
        },
        selectable: "row"
    });
});